﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;


namespace DAO
{
    public class NhanXetDAO
    {
        public void ThemNhanXet(shop_comment cmt)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.shop_comments.InsertOnSubmit(cmt);
            EFashionDB.SubmitChanges();

        }

        public List<shop_comment> LayNhanXetTheoMaSP(int MaSp)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListCmt = from cmt in EFashionDB.shop_comments
                          where cmt.MaSanPham == MaSp && cmt.TrangThai == true
                          select cmt;
            return ListCmt.ToList();
        }

        public void XoaNhanXet(int MaNX)
        {

            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListCmt = from cmt in EFashionDB.shop_comments
                          where cmt.MaComment == MaNX
                          select cmt;
            shop_comment ResultCmt = ListCmt.Single();
            EFashionDB.shop_comments.DeleteOnSubmit(ResultCmt);
            EFashionDB.SubmitChanges();
           
        }

        public void CapNhatTrangThaiNX(int MaNX, bool TrangThai)
        {

            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListCmt = from cmt in EFashionDB.shop_comments
                          where cmt.MaComment == MaNX
                          select cmt;

            foreach (shop_comment nx in ListCmt)
            {
                nx.TrangThai = TrangThai;
            }

            EFashionDB.SubmitChanges();

        }

        public List<shop_comment> LayTatCaNhanXet()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListCmt = from cmt in EFashionDB.shop_comments
                          select cmt;
            return ListCmt.ToList();
        }

        /************************************************************************************************************        *
         * coder: TRAN KINH LY 
         ***********************************************************************************************************/
        public List<shop_comment> LayDanhSach_NgayTaoGiamDan()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from cmt in EFashionDB.shop_comments
                       orderby cmt.NgayTao descending
                       select cmt;

            return list.ToList();
        }

        public shop_comment LayNhanXetTheoMa(int id)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_comment select = EFashionDB.shop_comments.Single(c => c.MaComment == id);
            return select;
        }

        public List<shop_comment> LayNhanXetTheoMaKhachHang_NgayTaoGiamDan(Guid id)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from cmt in EFashionDB.shop_comments
                       where cmt.UserId == id 
                       orderby cmt.NgayTao descending
                       select cmt;

            return list.ToList();
        }

        /************************************************************************************************************        *
         * coder: TRAN KINH LY 
         ***********************************************************************************************************/



        }
        

    }

